from os.path import dirname
from OpenSSL.crypto import PKey
from OpenSSL.crypto import TYPE_RSA, FILETYPE_PEM
from OpenSSL.crypto import dump_privatekey, dump_publickey
from OpenSSL.crypto import sign, verify
from OpenSSL.crypto import X509,Error
from OpenSSL.crypto import load_privatekey,load_certificate,dump_certificate
import base64
import time
import rsa
pk = PKey()

with open(dirname(__file__)+'/GLBFLH9V.crt','r') as f:
    sslcert = load_certificate(FILETYPE_PEM,f.read().encode())

with open(dirname(__file__)+'/GLBFLH9V.key','r') as f:
    sslprivkey = load_privatekey(FILETYPE_PEM,f.read().encode())

with open(dirname(__file__)+'/GLBFLH9V.key','r') as f:
    rsaprivkey = rsa.PrivateKey.load_pkcs1(f.read().encode())

n=300


begintime=time.time()
s='hello, world!'.encode('utf8')
for i in range(n):
    s=str(time.time()).encode('utf8')
    signature = rsa.sign(s, rsaprivkey, 'SHA-256')
#print(base64.b64encode(signature))
print(time.time()-begintime)

begintime=time.time()
for i in range(n):
    s=str(time.time()).encode('utf8')
    signature = sign(sslprivkey, s, 'sha256')
    #print(base64.b64encode(signature))
print(time.time()-begintime)
